package cn.lingyangwl.agile.pay.pay.process.transfer;

import cn.lingyangwl.agile.pay.common.service.TransferOrderService;
import cn.lingyangwl.agile.pay.pay.model.rqrs.transfer.QueryTransferOrderRQ;
import cn.lingyangwl.agile.pay.pay.model.rqrs.transfer.QueryTransferOrderRS;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import cn.lingyangwl.agile.pay.model.entity.TransferOrder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Service
public class QueryTransferOrderProcess {
    @Resource
    private TransferOrderService transferOrderService;

    /**
     * 查单接口
     */
    public Resp<?> queryTransferOrder(QueryTransferOrderRQ rq){
        if(StringUtils.isAllEmpty(rq.getMchOrderNo(), rq.getTransferNo())){
            throw new BizException("mchOrderNo 和 transferId不能同时为空");
        }

        TransferOrder refundOrder = transferOrderService.queryMchOrder(rq.getMchNo(), rq.getMchOrderNo(), rq.getTransferNo());
        if(refundOrder == null){
            throw new BizException("订单不存在");
        }

        QueryTransferOrderRS bizRes = QueryTransferOrderRS.buildByRecord(refundOrder);
        return Resp.ok(bizRes);
    }
}
